package ar.edu.unlp.info.cptn.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ar.edu.unlp.info.cptn.dao.PersonaDao;
import ar.edu.unlp.info.cptn.dto.PersonaDTO;
import ar.edu.unlp.info.cptn.model.Asignatura;
import ar.edu.unlp.info.cptn.model.Persona;
import ar.edu.unlp.info.cptn.service.PersonaService;

@Service
@Transactional
public class PersonaServiceImpl implements PersonaService {
	
	@Autowired
	PersonaDao personaDao;

	/*
	 * (non-Javadoc)
	 * @see ar.edu.unlp.info.cptn.service.PersonaService#getPersonasConAsignaciones()
	 */
	public Collection<PersonaDTO> getPersonasConAsignaciones() {
		Collection<Persona> personas = personaDao.getAll(Persona.class);
		PersonaDTO dto = null;
		List<PersonaDTO> dtos = new ArrayList<PersonaDTO>();
		for (Persona persona : personas){
			dto = new PersonaDTO(persona.getNombre(),persona.getApellido(),persona.getCursadas().size());
			dtos.add(dto);
		}
		return dtos;
	}

	public PersonaDao getPersonaDao() {
		return personaDao;
	}

	public void setPersonaDao(PersonaDao personaDao) {
		this.personaDao = personaDao;
	}

	@Override
	public List getAll(Class clazz){
		return this.getPersonaDao().getAll(clazz);
	}

	@Override
	public void guardar(Persona persona) {
		personaDao.guardar(persona);
		
	}

	/*
	 * (non-Javadoc)
	 * @see ar.edu.unlp.info.cptn.service.PersonaService#get(java.lang.Class, java.lang.Long)
	 */
	@Override
	public Object get(Class clazz, Long id) {
		return personaDao.get(clazz,id);
	}

	/*
	 * (non-Javadoc)
	 * @see ar.edu.unlp.info.cptn.service.PersonaService#login(java.lang.String, java.lang.String)
	 */
	@Override
	public Persona login(String usuario, String password) {
		return personaDao.login(usuario, password);
	}

	@Override
	public void guardar(Asignatura asignatura) {
		this.getPersonaDao().guardar(asignatura);
	}
	
}
